const { Server } = require("socket.io");
const { createServer } = require("http");
function createSocket(app) {
  const httpServer = createServer(app);

  const io = new Server(httpServer, {
    /* options */
    cors: {
      origin: "http://localhost:5173",
    },
  });

  io.on("connection", (socket) => {
    socket.emit("welcome", "Welcome to the server");
    socket.on("disconnect", () => {
      console.log("user disconnected");
      socket.broadcast.emit("userDisconnected", socket.id);
    });
  });
  httpServer.listen(3030);
}

module.exports = createSocket;
